x = list(input())
xl = list()
c = 0
if len(x) == 4:
    for i in range(1, 4):
        for t in range(0,4):
            if t + i <= 4:
                xl.append(x[t:t + i])
    for y in range(0,len(xl)):
        xl[y] = str(xl[y]).replace("[","")
        xl[y] = str(xl[y]).replace("'","")
        xl[y] = str(xl[y]).replace("]", "")
        xl[y] = str(xl[y].replace(",",""))
        xl[y] = str(xl[y]).replace(" ","")
        xl[y] = int(xl[y])
    xn = [-1] * len(xl)
    xn[0] = int(x[0] + x[1] + x[2] + x[3])
    for p in range(1,len(xl)):
        xn[p] = max(xl)
        xl[xl.index(max(xl))] = -1
    for u in range(0,len(xn)):
        if c == 1:
            print(xn[u - 1])
            break
        for o in range(2,xn[u] // 2 + 1):
            if xn[u] % o == 0:
                break
            if o == xn[u] // 2 and xn[u] * o != 0:
                c = 1
    if c == 0:
        print(0)
else:
    print(0)